DRCHEF Doctor Chef - CodeChef Solution


Array greedy

Python Code:

t = int(input())


def find(x, i):
    ans = 1

    while x < i:
        x = x * 2
        ans += 1
    return ans, i*2




for _ in range(t):
    n, x = map(int, input().split())
    s = list(map(int , input().split()))
    s.sort()

    if s.count(s[0]) == n:
        a, b = find(x, s[0])

        print(a + n-1)
        continue

    ind = -1

    count = 0


    for i in range(len(s)):
        if x<= s[i]:
            ind = i
            break

    if ind==-1:
        print(n)
        continue

    if ind!=0:
        ind-=1


    for i in range(ind, len(s)):

        if s[i]  * 2 <= x:
            count+=1
            continue

        b, x = find(x, s[i])

        count+=b

    print(count + ind)


Comments

Submit
0 Comments
More Questions

1574C - Slay the Dragon
621A - Wet Shark and Odd and Even
1395A - Boboniu Likes to Color Balls
1637C - Andrew and Stones
1334B - Middle Class
260C - Balls and Boxes
1554A - Cherry
11B - Jumping Jack
716A - Crazy Computer
644A - Parliament of Berland
1657C - Bracket Sequence Deletion
1657B - XY Sequence
1009A - Game Shopping
1657A - Integer Moves
230B - T-primes
630A - Again Twenty Five
1234D - Distinct Characters Queries
1183A - Nearest Interesting Number
1009E - Intercity Travelling
1637B - MEX and Array
224A - Parallelepiped
964A - Splits
1615A - Closing The Gap
4C - Registration System
1321A - Contest for Robots
1451A - Subtract or Divide
1B - Spreadsheet
1177A - Digits Sequence (Easy Edition)
1579A - Casimir's String Solitaire
287B - Pipeline